<template>
  <div class="app-container">
    <uc-table url="/admin/fireInfo/getFireInfoPage" name="火情信息" ref="fireInfoTable" pageable table-border
              :search-form="searchForm">
      <template slot="searchForm">
        <el-form size="mini" :inline="true" :model="searchForm" class="demo-form-inline filter-container">
          <!--搜索输入框-->
          <!--                    <el-form-item>-->
          <!--                        <el-input type="text" v-model="searchForm.name" placeholder="请输入火情名称" clearable @clear="clearInput()"></el-input>-->
          <!--                    </el-form-item>-->
          <el-form-item v-if="enterPriseHidden">
            <el-select v-model="searchForm.enterpriseId" placeholder="请选择企业" style="width: 100%" clearable
                       @clear="clearInput1()">
              <el-option v-for="(item,index) in enterpriseDominantList" :key="index" :value="item.ucId"
                         :label="item.name"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-select v-model="searchForm.fireDrill" placeholder="请选择火情类型" style="width: 100%" clearable>
              <el-option
                  v-for="dict in fireDrillOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
              />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-select v-model="searchForm.fireExecutionStatus" placeholder="请选择火情状态" style="width: 100%" clearable>
              <el-option
                  v-for="dict in fireStatusOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
              />
            </el-select>
          </el-form-item>
          <!--搜索按钮--新增按钮-->
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" class="filter-item" @click="handleSearch()">查询</el-button>
          </el-form-item>
        </el-form>
      </template>
      <template slot="columns">
        <!--                <el-table-column prop="name" label="火情名称" align="left" :show-overflow-tooltip="true"></el-table-column>-->
        <el-table-column prop="enterpriseName" label="所属主体" align="left"
                         :show-overflow-tooltip="true"></el-table-column>
        <!--                <el-table-column prop="fireAlarmName" label="火情预警名称 " align="left" :show-overflow-tooltip="true"></el-table-column>-->
        <!--                <el-table-column prop="buildName" label="建筑名称" align="left" :show-overflow-tooltip="true"></el-table-column>-->
        <el-table-column prop="loaction" label="详细地址 " align="left" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="fireConfirmTime" label="火情确定时间 " align="left" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            {{ scope.row.fireConfirmTime |dateFormat }}
          </template>
        </el-table-column>
        <el-table-column prop="fireDrill" label="火情类型" align="left" :formatter="fireDrillFormat" :show-overflow-tooltip="true"/>
        <el-table-column prop="fireExecutionStatus" label="火情状态" align="left" :formatter="fireStatusFormat" :show-overflow-tooltip="true">
        </el-table-column>
        <el-table-column prop="userName" label="确认用户名称 " align="left" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="address" label="操作" width="220" align="left" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <!--编辑按钮-->
            <el-button size="mini" icon="el-icon-edit" type="primary" @click="handleEdit(scope.row)">编辑</el-button>
            <el-button size="mini" icon="el-icon-info" type="success" @click="handleInfo(scope.row)">详情</el-button>
            <el-button size="mini" type="danger" icon="el-icon-delete" :loading="deleteLoading"
                       @click="handleDelete(scope.row)">删除
            </el-button>
          </template>
        </el-table-column>
      </template>
    </uc-table>
  </div>
</template>

<script>
import UcTable from "@/components/UcTable/index.vue";
import {deleteInFireInfo} from "@/api/fireInfo"
import {getInEnterpriseDominantList} from "@/api/enterpriseDominant";


export default {
  name: "fireInfoList",
  components: {UcTable},
  data() {
    return {
      searchForm: {
        deleted: false
      },
      deleteLoading: false,
      enterpriseDominantList: [],
      fireDrillOptions:[],
      fireStatusOptions: []
    }
  },
  computed: {
    enterPriseHidden() {
      let roleCode = this.$store.getters.roleCode;
      return roleCode == "ADMIN" || roleCode == "XT-ADMIN" || roleCode == "ZD-ADMIN" || roleCode == "DD-ADMIN" || roleCode == "JW-ADMIN" || roleCode == "XZ-ADMIN"
    }
  },
  created() {
    if(this.$route.params.fireDrill!=null){
      this.searchForm.fireExecutionStatus = this.$route.params.status
      this.searchForm.fireDrill = this.$route.params.fireDrill
    }
    this.getInEnterpriseDominantList()
    this.getDicts("fire_status").then(res => {
      if (res.data.data) {
        res.data.data.forEach(r => {
          this.fireStatusOptions.push({dictValue: parseInt(r.dictValue), dictLabel: r.dictLabel})
        })
      }
    })
    this.getDicts("fire_drill").then(res => {
      if (res.data.data) {
        res.data.data.forEach(r => {
          this.fireDrillOptions.push({dictValue: parseInt(r.dictValue), dictLabel: r.dictLabel})
        })
      }
    })
  },
  methods: {
    fireDrillFormat(row){
      return this.selectDictLabel(this.fireDrillOptions,row.fireDrill)
    },
    fireStatusFormat(row){
      return this.selectDictLabel(this.fireStatusOptions,row.fireExecutionStatus)
    },
    handleSearch() {
      this.$refs.fireInfoTable.getTableData(1)
    },
    handleEdit(val) {
      this.$router.push("/fireAlarm/fireInfoEdit?ucId=" + val.ucId)
    },
    handleInfo(val) {
      this.$router.push("/fireAlarm/fireInfoInfo/" + val.ucId)
    },
    clearInput() {
      //清除输入框
      this.searchForm.name = null
      this.handleSearch()
    },
    clearInput1() {
      //清除输入框
      this.searchForm.enterpriseId = null
      this.handleSearch()
    },
    clearInput2() {
      //清除输入框
      this.searchForm.fireExecutionStatus = null
      this.handleSearch()
    },
    getInEnterpriseDominantList() {
      getInEnterpriseDominantList({deleted: false}).then(res => {
        this.enterpriseDominantList = res.data
      })
    },
    handleDelete(val) {
      this.$confirm('您确定要执行删除' + val.name + '这个火情信息吗？', '提醒信息', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.deleteLoading = true
        deleteInFireInfo(val).then(res => {
          this.deleteLoading = false
          this.$notify.success({
            title: '成功',
            message: "删除火情信息成功"
          })
          this.handleSearch()
        }).catch(res => {
          this.deleteLoading = false
          this.$notify.error({
            title: '失败',
            message: res.msg
          })
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    }
  }
}
</script>

<style scoped>

</style>
